/**
 * Created by gm on 2016/9/26.
 */

var express=require('express');
var router=express.Router();

var monk=require('monk');
var db=monk('localhost:27017/usercollection');
var upMessage=db.get('upMessage');

router.get('/',function(req,res){
    upMessage.find({},function(err,data){
        if(err) throw err;
        res.json(data);
    });
});

router.post('/',function(req,res){
    if(req.body!=null){
        var pageSize=parseInt(req.body.pageSize);
        var skip=parseInt((req.body.p_current-1)*pageSize);
        upMessage.count({},function(err,data){
            if(err) throw err;
            upMessage.find({},{sort:{_id:-1},skip:skip,limit:pageSize},function(err,result){
                if(err) throw err;
                var jsonArray={count:data,result:result};
                res.json(jsonArray);
            });
        });
    }else{
        res.send('{"status":"failed"}');
    }
});

module.exports=router;
